<template>
	<el-col :span="componentModel.col*6" v-show="visible">
		<el-row>
			<el-col :span="8" class="field-label-div" v-if="!componentModel.noLabel">
				<label class="field-label">{{componentModel.label}}</label>
			</el-col>
			<el-col :span="componentModel.fieldcol">
				<el-date-picker type="datetime" placeholder="选择日期时间" @change="onChangeHandler" v-model="vue_model"
					:readonly="readonly" size="mini"></el-date-picker>
			</el-col>
		</el-row>
	</el-col>
</template>

<script>
	import {
		sendComponentValueChangeRequest
	} from '@/utils/requestUtils.js';
	import utils from '@/utils/utils.js';
	export default {
		name: "DatetimeComponent",
		props: ["componentModel", "scope"],
		data() {
			return {
				vue_model: "",
				visible: true,
				readonly: false,
				label: "",
			}
		},inject:['children'],
		mounted() {
			this.children.push(this);
		},beforeUnmount() {
			utils.removeArrayElement(this.children,this);
		},
		methods: {
			getValue() {
				if (this.vue_model == null || this.vue_model == "") {
					return "";
				} else {
					var sMonth = this.vue_model.getMonth() + 1 + "";
					if (this.vue_model.getMonth() + 1 < 10) {
						sMonth = "0" + (this.vue_model.getMonth() + 1);
					}
					var sDate = this.vue_model.getDate() + "";
					if (this.vue_model.getDate() + 1 < 10) {
						sDate = "0" + this.vue_model.getDate();
					}
					return this.vue_model.getFullYear() + "-" + sMonth + "-" + sDate + " " + this.vue_model.getHours() +
						":" + this.vue_model.getMinutes() + ":" + this.vue_model.getSeconds();
				}
			},
			setProp(prop) {
				for (var k in prop) {
					if (k == "value") {
						if (prop[k] == null) {
							this.vue_model = "";
						} else {
							var dateTimeArray = prop[k].split(" ");
							var dateArray = dateTimeArray[0].split("-");
							var timeArray = dateTimeArray[1].split(":");
							this.vue_model = new Date(parseInt(dateArray[0]), parseInt(dateArray[1]) - 1, parseInt(
									dateArray[2]),
								parseInt(timeArray[0]), parseInt(timeArray[1]), parseInt(timeArray[2]));
						}
					} else if (k == "visible") {
						this.visible = prop[k];
					} else if (k == "readonly") {
						this.readonly = prop[k];
					}else if(k=="label"){
						this.label = prop[k];
					}
				}
			},
			onChangeHandler() {
				if (this.scope != undefined) {
					this.$emit("onValueChange", this);
					return;
				}
				sendComponentValueChangeRequest(this);
			}
		}
	}
</script>

<style>
</style>
